{extend name="public:layout" /}
{block name="title"}栏目列表{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> 栏目列表</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="toolbar">
                <button class="btn btn-white" type="button"
                        onclick="updateOrder()">
                    <i class="fa fa-sort"></i> 更新排序
                </button>
                <button class="btn btn-white" type="button"
                        onclick="updateTpl()">
                    <i class="fa fa-bookmark"></i> 批量设置模板
                </button>
                <a class="btn btn-primary" href="{:url('add',['mid'=>$Request.param.mid])}">
                    <i class="fa fa-plus"></i>&nbsp;添加栏目
                </a>
                <a class="btn btn-primary" href="{:url('updateCache',['mid'=>$Request.param.mid])}">
                    <i class="fa"></i>&nbsp;更新缓存
                </a>
            </div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th width="50">#</th>
                    <th>排序</th>
                    <th>栏目名称</th>
                    <th>内容模型</th>
                    <th>绑定模板</th>
                    <th>是否显示</th>
                    <th width="150">操作</th>
                </tr>
                </thead>
                <tbody>
                {volist name="category" id="vo"}
                <tr id="{$vo.cid}" pId="{$vo.pid}">
                    <td>{$vo.cid}</td>
                    <td width="80">
                        <input type="text" class="form-control cat-order"
                               name="list_order[{$vo.cid}]" value="{$vo['cat_order']}"/>
                    </td>
                    <td>{$vo.cat_name}({$vo.cat_type_text})</td>
                    <td>{$vo.moudle_name}</td>
                    <td>
                        <input type="text" class="form-control cat-tpl" style="width:150px;"
                               name="list_tpl[{$vo.cid}]" value="{$vo['cat_tpl']}"/>
                    </td>
                    <td>{$vo.cat_show_text}</td>
                    <td>
                        <a href="{:url('add',['pid'=>$vo['cid'],'mid'=>$Request.param.mid])}">添加子栏目</a>
                        <a href="{:url('edit',['cid'=>$vo['cid'],'mid'=>$Request.param.mid])}">编辑</a>
                        <a href="javascript:;" onclick="doAction(this);"
                           data-params="mid={$vo.mid}&cid={$vo.cid}"
                           data-url="{:url('del')}"
                           data-msg="确认删除吗？">删除</a>
                    </td>
                </tr>
                {/volist}
                </tbody>
            </table>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        In('treetable',function(){
            var option = {
                theme: 'default',
                expandLevel: 2,
                column: 2,
                onSelect: function ($treeTable, id) {
                    window.console && console.log('onSelect:' + id);
                }
            };
            $('.table').treeTable(option);
        })
    });
    //更新排序
    function updateOrder() {
        if ($(".cat-order").length > 0) {
            var data = $(".cat-order").serialize();
            var mid="{$Request.param.mid}";
            var url = "{:url('updateOrder')}?mid="+mid;
            getAjax(url, data, function (data) {
                rePage();
            });
        }
    }
    function updateTpl() {
        if ($(".cat-tpl").length > 0) {
            var data = $(".cat-tpl").serialize();
            var mid="{$Request.param.mid}";
            var url = "{:url('updateTpl')}?mid="+mid;
            getAjax(url, data, function (data) {
                rePage();
            });
        }
    }
</script>
{/block}